//
//  SHMenuCell.m
//  吃货·上海
//
//  Created by lanou on 15/11/24.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "SHMenuCell.h"
#import "PrefixHeader.pch"
#import "UIImageView+WebCache.h"

@interface SHMenuCell ()

@property(nonatomic, strong)UIImageView *iconImageView;

@property(nonatomic,strong)UILabel *title;


@end

@implementation SHMenuCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight / 3)];
        self.iconImageView.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_iconImageView];
        
        UIView *view = [[UIView alloc]initWithFrame:self.iconImageView.frame];
        view.backgroundColor = [UIColor blackColor];
        view.alpha = 0.3;
        [self.contentView addSubview:view];
        
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
        longPress.minimumPressDuration = 0.5;
        [view addGestureRecognizer:longPress];
        
        self.title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 40)];
        self.title.font = [UIFont systemFontOfSize:17 weight:2];
        self.title.numberOfLines = 0;
        self.title.textAlignment = NSTextAlignmentCenter;
        self.title.textColor = [UIColor whiteColor];
        self.title.text = @"上海本地菜";
        self.title.center  = CGPointMake(self.iconImageView.frame.size.width / 2, self.iconImageView.frame.size.height / 2);
        [self.iconImageView addSubview:_title];
        
        self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.deleteBtn.frame = CGRectMake(0, 0 , 30, 30);
        self.deleteBtn.center = CGPointMake(self.center.x, self.center.y + 100);
        
        [self.deleteBtn setImage:[UIImage imageNamed:@"iconfont-delete-2"] forState:UIControlStateNormal];
        
        self.deleteBtn.hidden = YES;
        
        
        [self.contentView addSubview:_deleteBtn];
        
        
    }
    
    return self;
}

#pragma mark  - 赋值model
- (void)setModel:(SHMenuModel *)model
{
    _model = model;
    self.title.text = model.title;
    if (model.imageUrl != nil) {
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:@""]];
    }
}


- (void)longPress:(UILongPressGestureRecognizer *)longPress
{
    UIView *view = longPress.view;
    
    
        if (longPress.state == UIGestureRecognizerStateBegan) {
            [UIView animateWithDuration:0.5 animations:^{
                self.title.alpha = 0;
                view.alpha = 0;
            } completion:nil];
        }
        else if(longPress.state == UIGestureRecognizerStateEnded)
        {
            [UIView animateWithDuration:0.5 animations:^{
                self.title.alpha = 1;
                view.alpha = 0.3;
            }];
        }
    
}


@end
